'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const UserRole = app.model.define('english_user_roles', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    user_id: INTEGER(11),
    role_id: INTEGER(11),
    created_at: DATE,
    updated_at: DATE,
  }, {
    freezeTableName: true,
});

  UserRole.findByUserId = async function(user_id) {
    return await this.findAll({
      where: {
        user_id,
      },
      raw: true,
    });
  };
  return UserRole;
};
